#
# @lc app=leetcode.cn id=14 lang=python
#
# [14] 最长公共前缀
#

# @lc code=start
class Solution(object):
    def longestCommonPrefix(self, strs):
        """
        :type strs: List[str]
        :rtype: str
        """
        strs.sort(key=lambda x:len(x))

        result_str = ""
        if len(strs) == 0:
            return result_str
        elif len(strs) == 1:
            return strs[0]
        else:
            base_str = strs[0]

        for i in range(len(base_str)):
            base_word = base_str[i]
            for a_str in strs:
                if a_str[i] != base_word:
                    return result_str
            result_str += base_word
        return result_str

# @lc code=end

if __name__ == "__main__":
    solution = Solution()
    result_str = solution.longestCommonPrefix(["flower","flow","flight"])
    print(result_str)
